package com.adingxiong.cft.controller.mg;

import com.adingxiong.cft.entity.MgSysLog;
import com.adingxiong.cft.result.Result;
import com.adingxiong.cft.service.MgSysService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName MgSysLogController
 * @Description TODO
 * @Author xiongchao
 * @Date 2021/1/15 17:02
 **/
@RestController
@Api(tags = "mongo数据文档")
@RequestMapping("/mg")
public class MgSysLogController {

    @Autowired
    private MgSysService service;

    @PostMapping("/save")
    @ApiOperation(value = "创建文档数据")
    public Result save(@RequestBody MgSysLog log) {
        return Result.success(service.create(log));
    }

    @ApiOperation("删除浏览记录")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)

    public Result delete(@RequestParam("ids") List<String> ids) {
        int count = service.delete(ids);
        if (count > 0) {
            return Result.success(count);
        } else {
            return Result.failed();
        }
    }

    @ApiOperation("展示浏览记录")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<List<MgSysLog>> list(String memberId) {
        List<MgSysLog> memberReadHistoryList = service.findByOperation(memberId);
        return Result.success(memberReadHistoryList);
    }

}
